package com.shujia.spark.core

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Demo4Filter {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf()
    conf.setMaster("local")
    conf.setAppName("filter")

    val sc = new SparkContext(conf)

    //快速生成集合,to:含头含尾，until：含头不含尾
    val list: List[Int] = (0 until 100).toList

    val listRDD: RDD[Int] = sc.parallelize(list)

    /**
     * filter: 过滤数据，函数返回true保留数据，函数返回false过滤数
     *
     */
    val filterRDD: RDD[Int] = listRDD.filter((i: Int) => {
      val b: Boolean = i % 2 == 0
      b
    })

    filterRDD.foreach(println)

  }

}
